package com.lagou.email.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

@RestController
@RefreshScope
@RequestMapping("/api")
public class EmailController {
    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${lagou.message}")
    private String lagouMessage;


    @GetMapping("/email/{email}/{code}")
    public String sendEmail(@PathVariable(value = "email")  String email, @PathVariable(value = "code") String code) {

        System.out.println("====>>>>>>>>>>>>>>我是EmailController，访问到我这里了......"+code+email);

        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //发送方
        mailMessage.setFrom("990813997@qq.com");
        //接收方 youran9908@163.com
        mailMessage.setTo(email);
        //主题
        mailMessage.setSubject("注册验证码");
        //内容
        mailMessage.setText("您的注册验证码: "+code);


        //javaMailSender.send(mailMessage);

        return lagouMessage;
    }
}
